<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the number of fields contained in a result set</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.db2-next-result.html">« db2_next_result</a></li>
      <li style="float: right;"><a href="function.db2-num-rows.html">db2_num_rows »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.ibm-db2.html">IBM DB2 函数</a></li>
    <li>Returns the number of fields contained in a result set</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.db2-num-fields" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">db2_num_fields</h1>
  <p class="verinfo">(PECL ibm_db2 &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">db2_num_fields</span> &mdash; <span class="dc-title">
   Returns the number of fields contained in a result set
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.db2-num-fields-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>db2_num_fields</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>): <span class="type"><span class="type">int</span>|<span class="type"><span class="type false">false</span></span></span></div>



  <p class="para rdfs-comment">
   Returns the number of fields contained in a result set. This is most useful
   for handling the result sets returned by dynamically generated queries, or
   for result sets returned by stored procedures, where your application cannot
   otherwise know how to retrieve and use the results.
  </p>

 </div>

 <div class="refsect1 parameters" id="refsect1-function.db2-num-fields-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">stmt</code></dt>

     <dd>

      <p class="para">
       A valid statement resource containing a result set.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.db2-num-fields-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns an integer value representing the number of fields in the result
   set associated with the specified statement resource. Returns <strong><code>false</code></strong> if
   the statement resource is not a valid input value. 
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.db2-num-fields-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1278">
    <p><strong>示例 #1 Retrieving the number of fields in a result set</strong></p>
    <div class="example-contents"><p>
     The following example demonstrates how to retrieve the number of fields
     returned in a result set.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;id,&nbsp;name,&nbsp;breed,&nbsp;weight&nbsp;FROM&nbsp;animals&nbsp;ORDER&nbsp;BY&nbsp;breed"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">db2_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$columns&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_num_fields</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"There&nbsp;are&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$columns</span><span style="color: #007700">}</span><span style="color: #DD0000">&nbsp;columns&nbsp;in&nbsp;the&nbsp;result&nbsp;set."</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
There are 4 columns in the result set.
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.db2-num-fields-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.db2-execute.html" class="function" rel="rdfs-seeAlso">db2_execute()</a> - Executes a prepared SQL statement</span></li>
    <li class="member"><span class="function"><a href="function.db2-field-display-size.html" class="function" rel="rdfs-seeAlso">db2_field_display_size()</a> - Returns the maximum number of bytes required to display a column</span></li>
    <li class="member"><span class="function"><a href="function.db2-field-name.html" class="function" rel="rdfs-seeAlso">db2_field_name()</a> - Returns the name of the column in the result set</span></li>
    <li class="member"><span class="function"><a href="function.db2-field-num.html" class="function" rel="rdfs-seeAlso">db2_field_num()</a> - Returns the position of the named column in a result set</span></li>
    <li class="member"><span class="function"><a href="function.db2-field-precision.html" class="function" rel="rdfs-seeAlso">db2_field_precision()</a> - Returns the precision of the indicated column in a result set</span></li>
    <li class="member"><span class="function"><a href="function.db2-field-scale.html" class="function" rel="rdfs-seeAlso">db2_field_scale()</a> - Returns the scale of the indicated column in a result set</span></li>
    <li class="member"><span class="function"><a href="function.db2-field-type.html" class="function" rel="rdfs-seeAlso">db2_field_type()</a> - Returns the data type of the indicated column in a result set</span></li>
    <li class="member"><span class="function"><a href="function.db2-field-width.html" class="function" rel="rdfs-seeAlso">db2_field_width()</a> - Returns the width of the current value of the indicated column in a result set</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>